/**
 * Created by lixinkun on 2017/7/8.
 */
'use strict';
import * as types from '../actions/actionTypes';

const initState = {
    backgroundImage: null,
    loading: false,
    basic: null,
    nowWeather: null,
    suggestion: null,
    aqi: null,
    daily_forecast: null,
};

/**
 * 返回页面状态
 * @param state
 * @param action
 * @returns {*}
 */
export default function weatherDataState(state = initState, action) {
    switch (action.type){
        case types.FETCH_WEATHER_DATA_REQUEST:
            return Object.assign({}, state, {
                ...state,
                loading: true,
            });
        case types.FETCH_WEATHER_DATA_SUCCESS:
            return Object.assign({}, state, {
                ...state,
                loading: false,
                basic: action.basic,
                nowWeather: action.nowWeather,
                suggestion: action.suggestion,
                aqi: action.aqi,
                daily_forecast: action.daily_forecast,
            });
            return null;
        case types.FETCH_WEATHER_DATA_FAILURE:
            return Object.assign({}, state, {
                loading: false,
            });
        case types.FETCH_WEATHER_BACK_IMAGE_SUCCESS:
            return Object.assign({}, state, {
                ...state,
                backgroundImage: action.backgroundImage,
            });
        default:
            return state;
    }

}